/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DriverNoticia;

import java.io.*;
import java.net.*;

/**
 *
 * @author Juanma Fuentes Diaz
 */
public class DriverNoticia {

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static StringBuffer str = new StringBuffer();
            
    public static void main(String[] args) throws Exception {
        System.out.println("Escribe el archivo html, xml, txt (ejemplo en windows: c:\\web.html), o bien la direccion web. ");
        System.out.println();
        try {
            String fi = in.readLine();
            if (fi.substring(0, 4).compareTo("http")==0){
                URL page = new URL(fi);
                HttpURLConnection conn =(HttpURLConnection)page.openConnection();
                conn.connect();
                InputStreamReader inr = new InputStreamReader((InputStream) conn.getContent());
                BufferedReader buff = new BufferedReader(inr);
                String line;
                do{
                    line = buff.readLine();
                    str.append(line+" ");
                } while (line != null);
            }
            else{
            File f = new File(fi);
            BufferedReader di = new BufferedReader(new FileReader(f));
            String linea;
            do {
                linea = di.readLine();
                if (linea == null) {
                    break;
                } else {
                    str.append(linea+" ");
                }
            } while (true);
            }
        } catch (IOException e) {
            System.out.println("Error: " + e.getMessage());
        }
        ParserHttp not = new ParserHttp();
        if (not.esNoticia(str)){
            TitTex tt = new TitTex();
            tt = not.sacaTexto(str);
            System.out.println(tt.titulo+ " "+ tt.texto);
            Texto tx = new Texto(tt.titulo.concat(". "+tt.texto));
            }
        else System.out.println("Noticia no valida");
    }
}
